#ifndef STANDARDDATABASEMODEL_H
#define STANDARDDATABASEMODEL_H

#include <QSharedPointer>
#include <QStringList>
#include "abstract-section-model.h"
#include "sm-global.h"

class AbstractDatabaseClient;
class AbstractQueries;
class ModelResult;
class ValueListResult;

class StandardDatabaseModel : public AbstractSectionModel
{
    Q_OBJECT
public:
    explicit StandardDatabaseModel (QObject *parent = 0);

    virtual QVariant id (int row, int column = 0) const;
    virtual ValueResult* canSetRow (QVariantList dataList, int row = -1);
    virtual ValueResult* canAddData (QVariantList dataList);
    virtual ValueResult* canUpdateData (QVariant value, int row, int column);
    virtual QMap<int,QAbstractItemDelegate*> delegates() const;
    virtual SectionInfo sectionInfo() const;

    virtual int rowCount (const QModelIndex &parent = QModelIndex()) const;
    virtual int columnCount (const QModelIndex &parent = QModelIndex()) const;
    virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const;
    virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    virtual bool setData (const QModelIndex& index, const QVariant& value, int role);

public slots:
    virtual void setSectionInfo (const SectionInfo &sectionInfo);
    virtual void setLoadingParameters (QVariantList parameters);
    virtual void setIdColumnCount (int idColumnCount);
    virtual void initialize();
    virtual void loadData();
    virtual void addData (QVariantList dataList);
    virtual void updateData (QVariant data, int row, int column);
    virtual void removeData (QVariantList dataList);
    virtual void removeData (QVariant data);

protected slots:
    virtual void setupQueries();
    virtual void finishLoadData(ModelResult *result);
    virtual void finishCanSetRow(ValueResult *result);
    virtual void finishAddData (ValueResult* result);
    virtual void finishSetData (ValueResult *result);
    virtual void finishUpdateData(ValueResult *result);
    virtual void finishRemoveData(ValueResult *result);
    virtual void setupInternalModel();
    virtual void setupInternalModelHeader();

protected:
    QSharedPointer<AbstractDatabaseClient> m_databaseClient;
    QVariantList m_loadingParameters;
    QAbstractTableModel* m_internalModel;
    AbstractQueries* m_queries;
    QMap<int,QAbstractItemDelegate*> m_delegates;
    QStringList m_headerSections;
    QList<bool> m_permissions;
    int m_idColumnCount;
    QString m_dataAlreadyExistText;
};

#endif // STANDARDDATABASEMODEL_H
